package cn.edu.sdjzu.xg.kcsj.controller.basic;

import cn.edu.sdjzu.xg.kcsj.domain.StudentSign;
import cn.edu.sdjzu.xg.kcsj.service.StudentSignService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import util.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/insertStudentSign.ctl")
public class InsertStudentSignController extends HttpServlet {
    @Override
    protected void doPost (HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
        JSONObject respMessage = new JSONObject();
        resp.setContentType("application/json;charset=UTF-8");
        String req_jsonStr = JSONUtil.getJSON(req);
        StudentSign studentSignToAdd = JSON.parseObject(req_jsonStr,StudentSign.class);
        if (studentSignToAdd == null) {
            respMessage.put("message", "no have request");
            resp.getWriter().println(respMessage);
            return;
        }else{
            try {
                if(StudentSignService.getInstance().add(studentSignToAdd)){
                    respMessage.put("message", "add yes");
                }else {
                    respMessage.put("message", "add no");
                }
            }catch (SQLException e){
                respMessage.put("message", "sjk have exception");
            }catch(Exception e){
                respMessage.put("message", "wl have exception");
            }finally {
                resp.getWriter().println(respMessage);
            }
        }
    }
}
